#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "../lib/error.h"

int main(int argc,char *argv[])
{
    pid_t mypid,childpid;
    int n,i;

    if (argc != 2) {
        fprintf(stderr,"Parameter error!\n");
        fprintf(stderr,"Usag: %s process\n",argv[0]);
        exit(1);
    }

    mypid = getpid();
    fprintf(stderr,"mypid is %ld,my parent ID is %ld\n",(long)mypid,(long)getppid());

    n = atoi(argv[1]);
    for (i=0;i<n;i++) {
        if ((childpid = fork()) == 0) {
            break;
        }
    }
    mypid = getpid();
    fprintf(stderr,"%d: mypid is %ld,my parent ID is %ld,child ID is %ld\n",i,(long)mypid,(long)getppid(),
            (long)childpid);

    return 0;
}

